﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.UI.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security;
using DotNetNuke.Entities.Modules.Actions;
namespace TwentyTech.ToolTips
{
    public partial class edit : DotNetNuke.Entities.Modules.PortalModuleBase
    {

        private void RegisterScriptBlocks()
        {
            ClientAPI.RegisterClientScriptBlock(Page, "tooltips.edit.css", "<link rel=\"stylesheet\" href=\"" + ControlPath + "css/edit.css\" type=\"text/css\" media=\"screen\" />");
            ClientAPI.RegisterClientScriptBlock(Page, "tooltips.edit.js", "<script type=\"text/javascript\" src=\"" + ControlPath + "js/edit.js\"></script>");
            ClientAPI.RegisterClientScriptBlock(Page, "jquery.cookie.js", "<script type=\"text/javascript\" src=\"" + ControlPath + "js/jquery.cookie.js\"></script>");
            ClientAPI.RegisterClientScriptBlock(Page, "jquery.blockUI.js", "<script type=\"text/javascript\" src=\"" + ControlPath + "js/jquery.blockUI.js\"></script>");
            ClientAPI.RegisterClientScriptBlock(Page, "jquery.qtip.min.css", "<link rel=\"stylesheet\" href=\"" + ControlPath + "css/jquery.qtip.min.css\" type=\"text/css\" media=\"screen\" />");
            ClientAPI.RegisterClientScriptBlock(Page, "jquery.qtip.min.js", "<script type=\"text/javascript\" src=\"" + ControlPath + "js/jquery.qtip.min.js\"></script>");
            ClientAPI.RegisterClientScriptBlock(Page, "jquery-ui-1.8.12.custom.css", "<link rel=\"stylesheet\" href=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css\" type=\"text/css\" media=\"screen\" />");
            ClientAPI.RegisterClientScriptBlock(Page, "jquery-ui.min.js", "<script src=\"https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js\"></script>");
            
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterScriptBlocks();


            if (!Page.IsPostBack)
            {
                if (ToolTipController.GetToolTipInstance(ModuleId).Content != null)
                {
                    txtContent.Text = ToolTipController.GetToolTipInstance(ModuleId).Content;
                    txtConfigure.Text = Server.HtmlDecode(ToolTipController.GetToolTipInstance(ModuleId).Content);

                    BindToolTips();
                }
            }
        }


        protected void btnSaveContent_Click(object sender,EventArgs e)
        {
            ToolTipController.SaveContent(ModuleId, txtContent.Text);

            txtConfigure.Text = Server.HtmlDecode(ToolTipController.GetToolTipInstance(ModuleId).Content);
            BindToolTips();
        }

        protected void BindToolTips()
        {
            rptToolTips.DataSource = ToolTipController.GetToolTipInstance(ModuleId).ToolTips;
            rptToolTips.DataBind();

            rptToolTips2.DataSource = ToolTipController.GetToolTipInstance(ModuleId).ToolTips;
            rptToolTips2.DataBind();
        }

       
    }
}